Fix accels added after the window was shown not working
authorBastien Nocera <hadess@hadess.net>
Fri, 10 May 2013 14:04:11 +0000 (16:04 +0200)
committerBastien Nocera <hadess@hadess.net>
Mon, 13 May 2013 06:57:06 +0000 (08:57 +0200)
GtkApplicationWindow would only update its list of captured accels
when realizing the window. This meant that keyboard shortcuts added
after the window was realised (for example, added by plugins) would
be non-functional.

Solve this by updating our accels every time the accel map changes,
not only when realizing the window.

https://bugzilla.gnome.org/show_bug.cgi?id=700079

gtk/gtkapplicationwindow.c

index 541baf6a03145dd1212d74b497692ffb749be6fc..10fc58860b7ea17d0153709d483ff7b91394731d 100644 (file)
@@ -216,6 +216,7 @@ struct _GtkApplicationWindowPrivate
   GtkWidget *menubar;
   GtkAccelGroup *accels;
   GSList *accel_closures;
+  guint accel_map_changed_id;
 
   GMenu *app_menu_section;
   GMenu *menubar_section;
@@ -755,7 +756,12 @@ gtk_application_window_real_realize (GtkWidget *widget)
   gtk_application_window_update_shell_shows_app_menu (window, settings);
   gtk_application_window_update_shell_shows_menubar (window, settings);
   gtk_application_window_update_menubar (window);
+
+  /* Update the accelerators, and ensure we do again
+   * if the accel map changes */
   gtk_application_window_update_accels (window);
+  window->priv->accel_map_changed_id = g_signal_connect_swapped (gtk_accel_map_get (), "changed",
+                                                                G_CALLBACK (gtk_application_window_update_accels), window);
 
   GTK_WIDGET_CLASS (gtk_application_window_parent_class)
     ->realize (widget);
@@ -793,6 +799,7 @@ gtk_application_window_real_realize (GtkWidget *widget)
 static void
 gtk_application_window_real_unrealize (GtkWidget *widget)
 {
+  GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
   GtkSettings *settings;
 
   settings = gtk_widget_get_settings (widget);
@@ -800,6 +807,8 @@ gtk_application_window_real_unrealize (GtkWidget *widget)
   g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_app_menu_changed, widget);
   g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_menubar_changed, widget);
 
+  g_signal_handler_disconnect (gtk_accel_map_get (), window->priv->accel_map_changed_id);
+
   GTK_WIDGET_CLASS (gtk_application_window_parent_class)
     ->unrealize (widget);
 }